package com.xiaoma.myaudience.biz.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

import com.xiaoma.myaudience.biz.model.PlayRecordLoginInfo;
import com.xiaoma.myaudience.biz.model.PlayRecordNoLoginInfo;
import com.xiaoma.myaudience.biz.model.SearchHistoryInfo;
import com.xiaoma.myaudience.biz.model.SubscribeLoginInfo;
import com.xiaoma.myaudience.biz.model.SubscribeNoLoginInfo;
import com.xiaoma.myaudience.biz.model.UserAccount;
import com.xiaoma.myaudience.util.Logger;

public class AudienceDatabaseHelper extends SQLiteOpenHelper {
	public AudienceDatabaseHelper(Context context, String name,
			CursorFactory factory, int version) {
		super(context, name, factory, version);
		// TODO Auto-generated constructor stub
	}

	private static final String TAG = "VideoDatabaseHelper";

//	public AudienceDatabaseHelper(Context context) {
//		super(context, AudienceContentProvider.DATABASE_NAME, null, AudienceContentProvider.DATABASE_VERSION);
//	}

	@Override
    public void onCreate(SQLiteDatabase db) {
//        Logger.d(TAG, "creating new video database");
//        
//        clear(db);
//        
//        //未登录播放记录表
//        db.execSQL("CREATE TABLE " + AudienceContentProvider.TABLE_PLAY_RECORD_NO_LOGIN + " (" +
//                "_id INTEGER PRIMARY KEY," +
//                PlayRecordNoLoginInfo.PID + " TEXT," +
//                PlayRecordNoLoginInfo.VID + " TEXT," +
//                PlayRecordNoLoginInfo.TITLE + " TEXT," +
//                PlayRecordNoLoginInfo.VNUMBER + " INTEGER," +
//                PlayRecordNoLoginInfo.WATCH_TIME + " TEXT," +
//                PlayRecordNoLoginInfo.TIME_SPAN + " TEXT," +
//                PlayRecordNoLoginInfo.END_TAG + " INTEGER" +
//                ");");
//        
//        //已登录播放记录表
//        db.execSQL("CREATE TABLE " + AudienceContentProvider.TABLE_PLAY_RECORD_LOGIN + " (" +
//                "_id INTEGER PRIMARY KEY," +
//                PlayRecordLoginInfo.USERID + " TEXT," +
//                PlayRecordLoginInfo.PID + " TEXT," +
//                PlayRecordLoginInfo.VID + " TEXT," +
//                PlayRecordLoginInfo.TITLE + " TEXT," +
//                PlayRecordLoginInfo.VNUMBER + " INTEGER," +
//                PlayRecordLoginInfo.WATCH_TIME + " TEXT," +
//                PlayRecordLoginInfo.TIME_SPAN + " TEXT," +
//                PlayRecordLoginInfo.END_TAG + " INTEGER," +
//                PlayRecordLoginInfo.STATUS + " INTEGER" +
//                ");");
//        
//        //分类搜索列表
//        db.execSQL("CREATE TABLE " + AudienceContentProvider.TABLE_CATEGORY_SEARCH + " (" +
//        		"_id INTEGER PRIMARY KEY," +
//                CategorySearchItem.PARAM_PID + " NTEXT," +
//                CategorySearchItem.PARAM_TITLE + " NTEXT," +
//                CategorySearchItem.PARAM_DIGEST + " NTEXT," +
//                CategorySearchItem.PARAM_DIRECTOR + " NTEXT," +
//                CategorySearchItem.PARAM_IMG + " NTEXT," +
//                CategorySearchItem.PARAM_LAUNCH + " NTEXT," +
//                CategorySearchItem.PARAM_PERFORMER + " NTEXT," +
//                CategorySearchItem.PARAM_TYPE + " NTEXT," +
//                CategorySearchItem.PARAM_CATEGORY + " NTEXT," +
//                CategorySearchItem.PARAM_RATING + " FLOAT" +
//                ");");
//        
//        //未登录收藏表
//        db.execSQL("CREATE TABLE " + AudienceContentProvider.TABLE_SUBSCRIBE_NO_LOGIN + " (" +
//                "_id INTEGER PRIMARY KEY," +
//                SubscribeNoLoginInfo.PARAM_PID + " TEXT," +
//                SubscribeNoLoginInfo.PARAM_TITLE + " TEXT," +
//                SubscribeNoLoginInfo.PARAM_LAUNCH + " TEXT," +
//                SubscribeNoLoginInfo.PARAM_PERFORMER + " TEXT," +
//                SubscribeNoLoginInfo.PARAM_TYPE + " TEXT," +
//                SubscribeNoLoginInfo.PARAM_SCORE + " TEXT," +
//                SubscribeNoLoginInfo.PARAM_IMG + " TEXT" +
//                ");");
//        //已登录收藏表
//        db.execSQL("CREATE TABLE " + AudienceContentProvider.TABLE_SUBSCRIBE_LOGIN + " (" +
//                "_id INTEGER PRIMARY KEY," +
//                SubscribeLoginInfo.USERID + " TEXT," +
//                SubscribeLoginInfo.PARAM_PID + " TEXT," +
//                SubscribeLoginInfo.PARAM_TITLE + " TEXT," +
//                SubscribeLoginInfo.PARAM_LAUNCH + " TEXT," +
//                SubscribeLoginInfo.PARAM_PERFORMER + " TEXT," +
//                SubscribeLoginInfo.PARAM_TYPE + " TEXT," +
//                SubscribeLoginInfo.PARAM_SCORE + " TEXT," +
//                SubscribeLoginInfo.PARAM_IMG + " TEXT" +
//                ");");
//        
//        // 用户账号表
//        db.execSQL("CREATE TABLE " + AudienceContentProvider.TABLE_USER_ACCOUNT
//				+ " (" + "_id INTEGER PRIMARY KEY," + UserAccount.USERNAME
//				+ " TEXT," + UserAccount.PASSWORD + " TEXT,"
//				+ UserAccount.ISLOGIN + " INTEGER );");
//        
//        // 搜索记录表
//        db.execSQL("CREATE TABLE " + AudienceContentProvider.TABLE_SEARCH_HISTORY
//				+ " (" + "_id INTEGER PRIMARY KEY," + SearchHistoryInfo.KEYWORD
//				+ " TEXT," + SearchHistoryInfo.LASTUPDATETIME + " INTEGER );");
//        
    }

	private void clear(SQLiteDatabase db) {
//		db.execSQL("DROP TABLE IF EXISTS "+AudienceContentProvider.TABLE_PLAY_RECORD_NO_LOGIN);
//        db.execSQL("DROP TABLE IF EXISTS "+AudienceContentProvider.TABLE_PLAY_RECORD_LOGIN);
//        db.execSQL("DROP TABLE IF EXISTS "+AudienceContentProvider.TABLE_CATEGORY_SEARCH);
//        db.execSQL("DROP TABLE IF EXISTS "+AudienceContentProvider.TABLE_SUBSCRIBE_NO_LOGIN);
//        db.execSQL("DROP TABLE IF EXISTS "+AudienceContentProvider.TABLE_SUBSCRIBE_LOGIN);
//		db.execSQL("DROP TABLE IF EXISTS "+ AudienceContentProvider.TABLE_USER_ACCOUNT);
//		db.execSQL("DROP TABLE IF EXISTS "+ AudienceContentProvider.TABLE_SEARCH_HISTORY);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		Logger.d(TAG, "Upgrading database from version " + oldVersion + " to "
				+ newVersion + ", which will destroy all old data");
		// TODO ...以后更新数据库用
		// int version = oldVersion;
	}
}
